package EnumTest;

import com.sun.org.apache.bcel.internal.generic.BREAKPOINT;

public enum TestEnum {


    //枚举对象
    RED("RED",1),
    BLACK("BLACK",2),
    GREEN("GREEN",3);

    public String  color;
    public int oridinal ;

    TestEnum(String color , int oridinal){
        this.color = color ;
        this.oridinal = oridinal;
    }



    public static void main2(String[] args) {
        TestEnum[] testEnums = TestEnum.values();
        for(int i = 0 ; i < testEnums.length ; i++ ){
            System.out.println(testEnums[i] + " "+testEnums[i].ordinal());
        }

        System.out.println("=======");
        TestEnum testEnum = TestEnum.valueOf("GREEN");
        System.out.println(testEnum);
        System.out.println("=-=-=-=-=-=");
        System.out.println(RED.compareTo(BLACK)); //比较两个枚举成员定义时的顺序,因为BLACK的定义顺序比RED大所有返回负数
    }

    public static void main1(String[] args) {
        TestEnum testEnum = TestEnum.RED;

        //switch语句远古写法
        switch(testEnum){
            case BLACK :
                System.out.println("BLACK");
                break;
            case RED:
                System.out.println("RED");
                break;
            case GREEN:
                System.out.println("GREEN");
                break;
            default:
        }
        //switch语句优化写法  (仅限于jdk12)
//        switch(RED){
//            case RED -> System.out.println("RED");
//            case BLACK -> System.out.println("BLACK");
//            case GREEN -> System.out.println("GREEN");
//        }

    }
}


